﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using WitsWebApi.Entity.EntityParam;

namespace WitsWebApi.Entity.PageHelper
{
    public class PageDataContext<T>
    {
        /// <summary>
        /// 分页帮助类
        /// </summary>
        /// <param name="adminPageResult">分页传入参数</param>
        /// <param name="total">总数据条数</param>
        /// <param name="currentPageNum">当前页数据条数</param>
        /// <param name="result">返回数据结果集合</param>
        /// <returns></returns>
        public Paged<T> GetPagedData(dynamic adminPageResult, int total, int currentPageNum, dynamic result)
        {
            if (currentPageNum == 0 || total==0)
            {
                return new Paged<T>
                {
                    CurrentPage = adminPageResult.PageIndex,
                    TotalPages = adminPageResult.PageIndex,
                    ItemsPerPage = adminPageResult.PageSize,
                    TotalItems = total,
                    Items = null
                };
            }
            var list = new Paged<T>
            {
                CurrentPage = adminPageResult.PageIndex,
                TotalPages = (int)Math.Ceiling(total / currentPageNum * 1.0),
                ItemsPerPage = adminPageResult.PageSize,
                TotalItems = total,
                Items = result
            };
            return list;
        }
    }
}
